package cn.rongdao.jrkabao.dao;

import com.mifengkong.greendao.BaseGreenDao;

import java.lang.reflect.ParameterizedType;
import java.util.List;

/**
 * Created by jack on 2017/9/29
 */

public class BaseDao<T> extends BaseGreenDao<T> {

    @Override
    public String getDbName() {
        return "kamao.db";
    }

    public void updateBean(T obj){
        List<T> ts = queryAll(obj.getClass());
        if(ts== null || ts.size() ==0){
            insertObject(obj);
        }else {
            updateObject(obj);
        }
    }

    public T queryObject(){
        List<T> ts = queryAll((Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]);
        if(ts != null && ts.size()>0){
            return  ts.get(0);
        }
        return null;
    }
}